package com.ruoyi.web.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * TODO java类作用描述
 *
 * @author 徐岩松
 * @version 1.0
 * Copyright: Copyright (c) 2023
 * @date 2023/8/9 09:46
 */
@Slf4j
@Component
public class RabbitConfig implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnCallback {
    /**
     * 消息成功到达交换机触发该方法
     *
     * @param correlationData
     * @param ack
     * @param cause
     */
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (ack) {
            //消息成功到达交换机
            log.info("{}消息成功到达交换机", correlationData.getId());
        } else {
            log.error("{}消息未到达交换机,原因：{}", correlationData.getId(), cause);
        }

    }

    @Override
    public void returnedMessage(Message message, int i, String s, String s1, String s2) {
        log.info("message:{},i:{},s:{},s1:{},s2:{}", message.toString(), i, s, s1, s2);
    }
}
